<!--
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
-->

<!--
  Simple page for testing gadgets.rpc performance.
  Allows you to add a simulated "gadget" (in this case just a static
  HTML page which loads gadgets.rpc also), and pass some
  specified number of random messages of specified size to
  and from it.

  A simple recommended setup is to start up two instances of
  the Shindig Gadgets Server on two separate ports to test
  "real" cross-domain communication, since port is factored
  into the same-domain policy enforced by browsers.

  If your servers are on localhost:8080 and localhost:8081, then hit:
  http://localhost:8080/gadgets/files/container/rpctest_container.html? \
  http://localhost:8081/gadgets/files/container/rpctest_gadget.html& \
  http://localhost:8081/gadgets/files/container/rpc_relay.uncompressed.html

  (Note the backslashes should be removed, as they exist for formatting only.)

  There are two arguments, separated by an ampersand:
  1. URL of the "gadget" test page.
  2. URL of the "gadget" test page's RPC relay (for browsers requiring it).
-->
<html>
  <head>
    <title>gadgets.rpc Performance Tests: Container</title>
    <script src="../../js/rpc.js?c=1&debug=1"></script>
    <script src="rpctest_perf.js"></script>
    <script>
      function initTest() {
        var container = document.getElementById("container");

        // query string is assumed to be the "gadget" URL as arg 1,
        // and optionally the relay URL as arg 2
        var pageArgs = window.location.search.substring(1).split('&');
        var gadgetUrl = pageArgs[0];
        var secret = Math.round(Math.random()*10000000);
        if (pageArgs[1]) {
          gadgets.rpc.setRelayUrl('gadget', pageArgs[1]);
        }
        var containerRelay = pageArgs[2] || '';
        container.innerHTML = "<iframe id='gadget' name='gadget' height=300 width=300 src='" + gadgetUrl + "?parent=" + containerRelay + "#rpctoken=" + secret + "'></iframe>";
        gadgets.rpc.setAuthToken('gadget', secret);

        document.getElementById('relaymethod').innerHTML = gadgets.rpc.getRelayChannel();

        initPerfTest();
      };
    </script>
  </head>
  <body onload="initTest();">
    <div>gadgets.rpc Performance: Container Page (method: <span id="relaymethod"></span>)</div><hr/>
    <div>Test<br/>
      <ul>
        <li>Number of messages to send:
          <select name="num_msgs" id="num_msgs">
            <option value="1">1</option>
            <option value="10">10</option>
            <option value="100" selected>100</option>
            <option value="1000">1000</option>
          </select>
        </li>
        <li>Message size:
          <select name="msg_size" id="msg_size">
            <option value="10">10 B</option>
            <option value="100">100 B</option>
            <option value="1024" selected>1 kB</option>
            <option value="10240">10 kB</option>
            <option value="102400">100 kB</option>
            <option value="1048576">1 MB</option>
          </select>
        </li>
        <li>
          <input type="button" value="Start The Test!" onclick="runPerfTest('gadget');" />
        </li>
      </ul>
    </div>
    <div id="test_running" style="display:none;">
      Running test...
    </div>
    <div id="results" style="display:none;">
      Results: Gadget-to-Container<br/>
      Messages: <span id="results_num_received"></span>, Bytes: <span id="results_bytes_received"></span> <span id="in_or_out"></span><br/>
      Time elapsed for test run: <span id="results_time_used"></span><br/>
      Messages/second: <span id="results_msgs_per_sec"></span><br/>
      Bytes/second: <span id="results_bytes_per_sec"></span>
    </div>
    <hr/>
    <div>Gadget:</div>
    <div id="container"></div>
  </body>
</html>
